package 考试;
//使用List集合存储6个学生信息。学生信息：姓名、年龄、成绩。统计所有姓“张”的同学的平均成绩。
import java.util.*;
class Student {
 String name;
 int age;
 double score;
    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }
public String getName() {
        return name;
    }
public double getScore() {
        return score;
    }
}
public class task1存储6个学生信息 {
	 public static void main(String[] args) {
		List<Student> students = new ArrayList<>();
	        students.add(new Student("徐二丫", 20, 91));
	        students.add(new Student("张二", 22, 92));
	        students.add(new Student("张张", 21, 99));
	        students.add(new Student("董三丫", 3, 78.2));
	        students.add(new Student("赵四丫", 4, 90.5));
	        students.add(new Student("刘五丫", 5, 76.4));
	        
      double sum = 0;
	        int count = 0;
	        
	        for (Student student : students) {
	            if (student.getName().startsWith("张")) { 
	                sum += student.getScore();
	                count++;
	            }
	        }

	         if (count > 0) {
	            double average = sum / count;
	            System.out.println("所有姓'张'的同学的平均成绩: " + average);
	        } else {
	            System.out.println("没有姓'张'的同学。");
	        }
	    }
}
